// 扁平数据转树形
export default function toTree(data, currentKey = 'id', parentKey = 'parentId', childKey = 'children') {
    // 存储树形数据的数组
    let treeArr = []
    function recursion(data) {
        data.forEach(item => {
            if (item[parentKey]) {
                let parent = data.find(p => p[currentKey] === item[parentKey])
                if (!parent[childKey]) {
                    parent[childKey] = []
                }
                parent[childKey].push(item)
            } else {
                treeArr.push(item)
            }
        })
    }
    recursion(data)
    return treeArr
}